/*
 * @lc app=leetcode.cn id=3 lang=golang
 *
 * [3] 无重复字符的最长子串
 */

// @lc code=start
func lengthOfLongestSubstring(s string) int {
	i,j:=0,0
	hm:=make(map[byte]int)
	maxLength:=0
	for j=0;j<len(s);j++{
		if v,ok:=hm[s[j]];ok{
			if v>=i{
				maxLength = max(maxLength,j-i)
				i = v+1
			}
		}
		
		hm[s[j]] = j
	}

	return max(maxLength,len(s)-i)
}

func max(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

// @lc code=end

